
//数据接口域名
var website = "http://api.cibn.onairm.cn/";

(function () {
    function w() {
        var r = document.documentElement;
        var a = r.getBoundingClientRect().width;
        if (a > 750) {
            a = 750;
        }
        //750/w = 100/font-size
        rem = a / 7.5;
        r.style.fontSize = 2 * rem + "px"
    }

    var t;
    w();
    window.addEventListener("resize", function () {
        clearTimeout(t);
        t = setTimeout(w, 300)
    }, false);
})();
var fsize = parseFloat($("html").css("font-size"));
//基础参数
var par_ty;
var par_v = '1.0.0';
var par_dk;
var par_tn;
var par_userId;//若用户登录时传入用户id，若没有登陆时 ‘childWap’+ 随机16位字符

var COOKIE_UUID = "COOKIE_UUID";
var COOKIE_USERID = "COOKIE_USERID";
function myempty(str) {
    return !str;
}
//格式化地址
function formatFileUrl(url, url_bak, flag) {
    var file = url;
    if (myempty(file)) {
        if (myempty(url_bak)) {
            if (flag == 1) {
                file = '1ab8bb5a26d89901a604162766ba0fee';
            }
        } else {
            file = url_bak;
        }
    }
    var gameUrl = 'http://img.paas.onairm.cn/';
    var fileUrl = '';
    if (file.indexOf("http://") === 0) {
        fileUrl = file;
    } else {
        fileUrl = gameUrl + file;
    }

    return fileUrl;
}
// 格式化地址（对图片进行裁剪）info为1的时候是大图(w:3.75,h:2.11)，2为小图(w:1.73,h:0.98);
function formatFileUrlImgCut(url, url_bak, flag, info) {
    var file = url;
    //     info为1的时候是大图(w:3.75,h:2.11)，2为小图(w:1.73,h:0.98);
    var img = {};
    if (info == 2) {
        img.width = parseInt(1.73 * fsize);
        img.height = parseInt(0.98 * fsize);
    } else {
        img.width = parseInt(3.75 * fsize);
        img.height = parseInt(2.11 * fsize);
    }
    if (myempty(file)) {
        if (myempty(url_bak)) {
            if (flag == 1) {
                file = '1ab8bb5a26d89901a604162766ba0fee';
            }
        } else {
            file = url_bak;
        }
    }
    var gameUrl = 'http://img.paas.onairm.cn/'; //qi niu
    var fileUrl = '';
    if (file.indexOf("http://") === 0) {
        if (file.indexOf(gameUrl) > -1) {
            if (file.indexOf("?") > -1) {
                if (file.lastIndexOf("?") === 0) {
                    fileUrl = file + 'imageView2/2/w/' + img.width + '/h/' + img.height;
                } else {
                    fileUrl = file + '|imageView2/2/w/' + img.width + '/h/' + img.height;
                }
                ;
            } else {
                fileUrl = file + '?imageView2/2/w/' + img.width + '/h/' + img.height;
            }
        } else {
            fileUrl = file;
        }
    } else {
        fileUrl = gameUrl + file + '?imageView2/2/w/' + img.width + '/h/' + img.height;
    }
    ;
    fileUrl = encodeURI(fileUrl);
    return fileUrl;
}
//返回上一页函数
function backToLastPage() {
    window.history.go(-1);
    /*var categoryId = localStorage.categoryId;
     window.location.href = "index.html"+(categoryId || '');*/
}
function GetQueryString(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
//    var loc = decodeURI(window.location);
    var r = decodeURI(window.location.search).substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}
function randomString(len) {
    var len = len || 32;
    var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
    var maxPos = $chars.length;
    var pwd = '';
    for (i = 0; i < len; i++) {
        pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
    }
    return pwd;
}
//构造参数
function initPar() {
    par_ty = 'web';
    var index_dk;
    index_dk = $.cookie(COOKIE_UUID);

    if (index_dk && index_dk.length === 16) {
        par_dk = $.cookie(COOKIE_UUID);
    } else {
        par_dk = randomString(16);
        $.cookie(COOKIE_UUID, par_dk, {path: '/', expires: 1});
    }
    par_dk = randomString(16);
    par_userId = 'cbn' + par_dk;
    var cuid = $.cookie(COOKIE_USERID);
    if (cuid) {
        par_userId = cuid ? cuid : par_userId;
    }
    par_tn = randomString(16) + hex_md5(par_userId + par_ty + par_v + par_dk);
    return {dk: par_dk, ty: par_ty, v: par_v, tn: par_tn, userId: par_userId};
}

//根据秒数格式化时间
function initTimeLength(timeLength) {
    timeLength = parseInt(timeLength);
    var second = timeLength % 60;
    var minute = (timeLength - second) / 60;
    return (minute < 10 ? "0" + minute : minute) + ":" + (second < 10 ? "0" + second : second);
};

